using System.Collections.Generic;
using System.Collections;
using System.Linq.Expressions;

namespace DaphneTranslator.BusinessLogic
{
	/// <summary>
	/// LanguageText - one key row text
	/// </summary>
	public class LanguageText
	{
		public string Key
		{ get; set; }
		
		public string ValueXmlKey
		{ get; set; }
		
		public string Value
		{ get; set; }
	}
	
	public class LanguageFile
	{
		public string Culture
		{ get; set; }
		
		public string OriginalFilePath	
		{ get; set; }
		
		public string RelativePath
		{ get; set; }
		
		public string Filename
		{ get; set; }
		
		public string EnglishName
		{ get; set; }
		
		public string CultureName
		{ get; set; }

        public List<LanguageText> Texts
        { get; set; }

        public CultureRecord Parent
        { get; set; }

		
		public LanguageFile ()
		{
			Texts = new List<LanguageText> ();		
		}
		
		public LanguageText FindTextByKey (string sKey)
		{
			foreach (var item in Texts) {
				if (item.Key == sKey)
					return item;
			}
			
			return null;					
		}
	}
	
	public class MappedFileCollection: List<string>
	{
        public string CultureCode
        { get; set; }

		public MappedFileCollection ()
			:base ()
		{
		}
	}
	
	public class FileMapper
	{
		List<MappedFileCollection> MappedFiles;
		
		public FileMapper ()
		{
			MappedFiles = new List<MappedFileCollection> ();
		}
		
		public MappedFileCollection GetCollectionByFile (string sFile)
		{
			foreach (var collection in MappedFiles) {
				if (collection.Contains (sFile))
					return collection;
			}
			
			return null;
		}
		
		public MappedFileCollection GetCollectionByFileSubString (string sSubString)
		{
			foreach (var collection in MappedFiles) {
				foreach (string sFilePath in collection) {
					if (sFilePath.Contains (sSubString))
						return collection;
				}
			}
			
			return null;			
		}
		
		public void CreateNewCollection (string sFirstFilePath)
		{
			MappedFileCollection collection = new MappedFileCollection ();
			collection.Add (sFirstFilePath);
			MappedFiles.Add (collection);
		}

        public MappedFileCollection GetCollectionByCultureCode(string sCode)
        {
            foreach (var item in MappedFiles)
            {
                if (item.CultureCode == sCode)
                    return item;
            } // foreach

            return null;            
        }
	}
	
	
	/// <summary>
	/// Language list.- collection of texts
	/// </summary>
	public class CultureRecord
	{
		private string _sEnglishName;
		private string _sCultureName;
		
		
		public string Culture
		{ get; set; }
		
		public string EnglishName { 
			get {
				return _sEnglishName;
			}
			set {
				_sEnglishName = value;
				foreach (var item in Files)
					item.EnglishName = value;
			}
		}
		
		public string CultureName { 
			get {
				return _sCultureName;
			}
			set {
				_sCultureName = value;
				foreach (var item in Files)
					item.CultureName = value;
			}
		}

        public CultureCollection Parent
        { get; set; }
	
		
		public List<LanguageFile> Files;
		
					
		
		public CultureRecord ()
		{
			Files = new List<LanguageFile> ();
		}

        public void AddFile(LanguageFile file)
        {
            file.Parent = this;
            Files.Add(file);
        }
	}	
	
	public class CultureCollection
	{
		public List<CultureRecord> CultureList
		{ get; set; }
		
		public IMapper MapperEngine
		{ get; set; }
		
		public FileMapper FileMapperContainer
		{ get; set; }
		
		
		public CultureCollection ()
		{
			CultureList = new List<CultureRecord> ();
			FileMapperContainer = new FileMapper ();			
		}

        public void AddCulture(CultureRecord cr)
        {
            cr.Parent = this;
            this.CultureList.Add(cr);
        }

        public CultureRecord CreateNewCulture(string sCultureCode, string sEnglishName, string sCultureName)
        {
            CultureRecord cr = new CultureRecord();
            cr.Culture = sCultureCode;
            cr.CultureName = sCultureName;
            cr.EnglishName = sEnglishName;
            cr.Parent = this;

            this.CultureList.Add(cr);
            return cr;
        }
	}
}
		
		
		
